<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	request.setAttribute("basePath",basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp"%>
<%@ include file="/resources/js/wechat/_wechatui.jsp"%>
<%@ include file="/resources/js/easyui/_viewJS.jsp"%>
<!DOCTYPE>
<html>
<head>
	<title>套餐</title>
</head>
<body>
<div class="loading"></div>
<!-- header -->
<header>
	<a href="${basePath}wechat/discount/showView" class="top_fh">套餐编辑</a>
	<a href="JavaScript:;" class="top_add"></a>
</header>
<!-- header end -->

<div class="page">
	<form id="editform">
		<c:forEach items="${list}" var="discount" varStatus="status">
			<div class="swiper-container">
				<div class="swiper-wrapper">
					<ul class="swiper-slide swiper">
						<li>套餐编号：<span>${status.index+1}<input type="hidden" name="discountid" value="${discount.discountid}" /></span></li>
						<li>套餐名称：<span>${discount.discountname}</span></li>
						<li>套餐单价：<input type="type" class="money" id="money${status.index+1}" name="money" value="${discount.money}" /></li>
						<li>套餐币数：<input type="type" class="coin" id="coin${status.index+1}" name="coin" value="${discount.coin}" /></li>
					</ul>
					<div class="swiper-slide swiperbtn">
						<a href="${basePath}wechat/discount/${discount.discountid}/editView/${status.index+1}">编辑</a>
						<a href="JavaScript:;" action="remove" onclick="view.remove(${discount.discountid})" >删除</a>
					</div>
				</div>
			</div>
		</c:forEach>
	</form>
	<div class="tcbj_button"><a href="JavaScript:;" id="saveBtn">保存</a></div>
</div>

<!-- footer -->
<%@include file="/WEB-INF/jsp/wechat/_footer.jsp"%>
<!-- footer end -->

<!-- top加号弹窗 -->
<%@include file="/WEB-INF/jsp/wechat/_top.jsp"%>
<!-- top加号弹窗 end -->
</body>
<script type="application/javascript">
	function View(){
		var that = this;

		that.events = [
			{ sel : '#saveBtn', act : 'click', func : 'saveSub' },
			{ sel : 'a[action="remove"]', act : 'click', func : 'remove' }
		];

		that.saveSub = function(){
			var reg = /^\+?[1-9][0-9]*$/;
		<c:forEach items="${list}" var="discount" varStatus="status">
			var money${status.index+1} = $("#money${status.index+1}").val();
			var coin${status.index+1} = $("#coin${status.index+1}").val();
			if(!reg.test(money${status.index+1})){
				$("#money${status.index+1}").css("border","2px solid #F00");

				return false;
			}else if(!reg.test(coin${status.index+1})){

				$("#coin${status.index+1}").css("border","2px solid #F00");

				return false;
			}
		</c:forEach>

				$.ajax({
					url:'${basePath}wechat/discount/editBatch',
					type : 'POST',
					traditional: true,
					data : $('#editform').serialize(),
					error: function (response) {
						ViewHelper.func.ajaxWechatErrorMessage(response);
					},
					success: function (ret) {
						if(ret.result) {
							window.location = "${basePath}wechat/discount/showView";
						}else{
							alert(ret.info);
						}
					}
				});

		};

		that.remove = function(id){
			$.ajax({
				url:'${basePath}wechat/discount/delete',
				type : 'POST',
				data : {"discountId":id},
				error: function (response) {
					ViewHelper.func.ajaxWechatErrorMessage(response);
				},
				success: function (ret) {
					if(ret.result) {
						window.location = "${basePath}wechat/discount/listView";
					}else{
						alert(ret.info);
					}
				}
			});
		};

		EventHandler.call(that, that.events);

		return that;
	}

	var view;

	$(function(){
		inherit(View, EventHandler);
		view = new View();
	});

	<c:forEach items="${list}" var="discount" varStatus="status">
	$("#money${status.index+1}").long({"element":"#money${status.index+1}","action":"keyup","stringl":"0","stringls":"3","reg":/^\+?[1-9][0-9]*$/,"stavalue":""});
	$("#coin${status.index+1}").long({"element":"#coin${status.index+1}","action":"keyup","stringl":"0","stringls":"3","reg":/^[123456789]\d{0,9}$/, "stavalue":""});
	</c:forEach>


	var swiper = new Swiper('.swiper-container', {
		direction: 'horizontal',   //滑动方向
		loop: false,     //环，使成环
		slidesPerView: 'auto',
		centeredSlides: false,
	});
</script>
</html>
